#include <bits/stdc++.h>
#include <string>
using namespace std;

int main()
{
  int n, m, k, count = 0;
  // 开始灯号 结束灯号
  start = 0, end = 0;
  cin >> n >> m;
  // 记录灯的点亮状态 0未点亮 1点亮
  int light[n + 1] = {0};
  for (int i = 0; i < m; i++)
  {
    cin >> k;
    if (!i)
    {
      light[k] = 1;
      count++;
      start = k;
    }
    else
    {
      // 左侧灯号    右侧灯号
      int left = k - 1 ? k - 1 : n, right = k + 1 > n ? 1 : k + 1;
      if (light[left] || light[right])
      {
        light[k] = 1;
        count++;
      }
      if (count == n)
      {
        end = k;
        cout << start << " " << end << endl;
        return 0;
      }
    }
  }
  cout << "No";
  return 0;
}
